<!--
 * Copyright 2019 ia-cloud project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 -->

<script type="text/html" data-template-name="HMI-Schneider-com">
  <div class="form-row">
    <label for="node-config-input-IPAdd"><span data-i18n="editor.netAddress"></span><span style="color: #ff0000;">*</span></label>
    <input type="text" style="width: 300px" id="node-config-input-IPAdd">
  </div>
  <div class="form-row">
    <label for="node-config-input-TCPPort"><span data-i18n="editor.TCPPort"></span><span style="color: #ff0000;">*</span></label>
    <input type="number" style="width: 300px" id="node-config-input-TCPPort">
  </div>
  
  <div class="form-row">
    <input type="checkbox" id="node-config-input-details" style="display: inline-block; width: auto; vertical-align: top;">
    <label for="node-config-input-details" style="width: 70%;"><span data-i18n="editor.details"></span></label>
    <div style="margin-left: 20px" class="node-config-input-details-row hide">
      <div class="form-row">
        <label for="node-config-input-MaxSocket"><span data-i18n="editor.MaxSocket"></span></label>
        <input type="number" style="width: 300px" min="1" max="5" id="node-config-input-MaxSocket">
      </div>
    </div>
  </div>

  <hr>

  <div class="form-row">
    <label for="node-config-input-name"><i class="fa fa-tag"></i><span data-i18n="editor.name"></span></label>
    <input type="text" id="node-config-input-name">
  </div>
</script>

<script type="text/javascript">

  RED.nodes.registerType('HMI-Schneider-com',{
    category: 'config',
    defaults: {
      name: {value:"SchneiderHMI"},
      IPAdd:{value:"127.0.0.1", required:true },
      TCPPort:{value:"8082", validate: RED.validators.number(), required:true },
      MaxSocket:{value:5},
    },

    label: function() {
      return this.name||this._("HMI-Schneider-com");
    },
    
    oneditprepare: function() {
      $("#node-config-input-details").change(function() {
        if ($(this).is(":checked")) {
          $(".node-config-input-details-row").show();
        } else {
          $(".node-config-input-details-row").hide();
          $('#node-config-input-MaxSocket').val(5);
        }
      });
      if ((!$('#node-config-input-MaxSocket').val()) || ($('#node-config-input-MaxSocket').val() == 5))
      {
        $('#node-config-input-MaxSocket').val(5);
        $('#node-config-input-details').prop('checked', false);
      } else {
        $('#node-config-input-details').prop('checked', true);
      }
      $("#node-config-input-details").change();
    }
  });

</script>
